#pragma once
//////////////////////////////////////////////////////////////////////////
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Data;
using namespace System::Globalization;
//////////////////////////////////////////////////////////////////////////
NAMESPACE_BEGIN_UI
//////////////////////////////////////////////////////////////////////////
[ValueConversionAttribute(ManagedArr::typeid, BitmapSource::typeid)]
public ref class ManagedImageConverter : IValueConverter
{
public:
	static BitmapPalette^ CreateGray8DepthPalette();
	static BitmapPalette^ CreateGray16DepthPalette();

private:
	static array<unsigned long>^ ConvertBitmapPaletteToArray(BitmapPalette^ palette);
	static void FillBitmapData8U1C(WriteableBitmap^ data, void* pLine0, int stride, BitmapPalette^ palette);
	static void FillBitmapData16U1C(WriteableBitmap^ data, void* pLine0, int stride, BitmapPalette^ palette);
	static void FillBitmapData8U3C(WriteableBitmap^ data, void* pLine0, int stride);
	static void FillBitmapData8U4C(WriteableBitmap^ data, void* pLine0, int stride);
	static WriteableBitmap^ BuildBitmapFromCache(ManagedImage^ img, WriteableBitmap^ cache);
	static WriteableBitmap^ BuildBitmapFromCache(ManagedMat^ img, WriteableBitmap^ cache);
	static bool CheckPixelFormatIsSupport(ManagedImage^ img);
	static bool CheckPixelFormatIsSupport(ManagedMat^ img);

public:
	static WriteableBitmap^ Convert(ManagedArr^ img, WriteableBitmap^ cache, BitmapPalette^ palette);
	static ManagedImage^ Convert(WriteableBitmap^ bitmap, ManagedImage^ cache);

public:
	virtual System::Object^ Convert(System::Object^ value, System::Type^ targetType, System::Object^ parameter, CultureInfo^ culture);
	virtual System::Object^ ConvertBack(System::Object^ value, System::Type^ targetType, System::Object^ parameter, CultureInfo^ culture);
};
//////////////////////////////////////////////////////////////////////////
NAMESPACE_END_UI
//////////////////////////////////////////////////////////////////////////